package com.JustTest;

import org.apache.kafka.clients.KafkaClient;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.producer.Callback;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.Properties;

/**
 * Created by mike on 18/1/31.
 */
public class Consumer {
    public static void main(String[] args) {
        Properties properties = new Properties();
        properties.setProperty("bootstrap.servers","localhost:9092,localhost:9093,localhost:9094");
        properties.setProperty("key.deserializer","org.apache.kafka.common.serialization.StringDeserializer");
        properties.setProperty("value.deserializer","org.apache.kafka.common.serialization.StringDeserializer");
        properties.setProperty("group.id","GROUP5");
        properties.setProperty("auto.offset.reset","earliest");
        KafkaConsumer<String,String> consumer = new KafkaConsumer<String, String>(properties);
        consumer.subscribe(Collections.singletonList("mytest2"));
        while(true) {
            ConsumerRecords<String, String> records = consumer.poll(3);
           for(ConsumerRecord<String,String> record:records){
               System.out.println("topic:" + record.topic()+" key:" + record.key()+" value:" + record.value() +" partition:" +record.partition());
           }
        }
    }
}
